<?php
ob_start();
session_start();
$page='main_forum';
include_once 'header.php';
include 'connect/connect.php';
$tbl_name="forum_answer";
extract($_POST);
$id=$_POST['id'];
$sql="SELECT MAX(a_id) AS Maxa_id FROM $tbl_name WHERE question_id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_assoc($result);
if ($rows) {
$Max_id = $rows['Maxa_id']+1;
}
else {
$Max_id = 1;
}
$a_name=$_SESSION['username'];
$a_answer=$_POST['a_answer']; 

$datetime=date("d/m/y H:i:s"); 
$sql2="INSERT INTO $tbl_name(question_id, a_id,  a_answer,a_name, a_datetime)VALUES('$id', '$Max_id',  '$a_answer','$a_name', '$datetime')";
$result2=mysql_query($sql2)or die("Error executing '$sql2':" . mysql_error());
if($result2){
header("location:view_topic.php?id=$id");
}
else {
echo "ERROR";
}
mysql_close();
ob_flush();
 include_once 'footer.php';
?>

